<div class="box"> 
	<div class="title">
		<h5><?php echo lang('text_heading_title_site_list') ?></h5>
	</div>
	
	<table class="table table-condensed table-striped table-hover table-bordered pull-left" id="records">                        
	<thead>
	<tr>
		<!-- <th style="width:5%">#</th> -->
		<th style="width:10%">Site ID</th>
		<th style="width:10%">Reference Site ID</th>
		<th style="width:10%">Site Name</th>		
		<th style="width:10%">Nominal Latitude</th>
		<th style="width:10%">Nominal Longitude</th>
		<th style="width:10%">Site Address</th>
		<!-- <th style="width:10%">Active</th> -->
		<th style="width:10%">Action</th>
	</tr>
	</thead>
	<tbody></tbody>
	</table>
</div>

<script type="text/template" id="tplMasterSite">
	<tr id="${site_id}">
		<!-- <td width="30px">${nomor}</td> -->
		<td>${site_id_text}</td>
		<td>${old_site_id}</td>
		<td>${site_name}</td>		
		<td>${latitude}</td>
		<td>${longitude}</td>
		<td>${site_address}</td>
		<!-- <td>${active}</td> -->
		<td width="110px" style="text-align:center">
			<?php
			$link = array();
			
			$prev = get_instance()->site_info_model->get_privilege_actions(335, get_instance()->session->userdata('group'));
			
			if ($prev) {
				if ($prev['menu_view'] == 1) {
					$link[] = anchor(site_url('/site_info/show').'/${site_id}', 'View');
				}
				if ($prev['menu_edit'] == 1) {
					$link[] = anchor(site_url('/site_info/edit').'/${site_id}', 'Edit');
				}
				if ($prev['menu_delete'] == 1) {
					$link[] = anchor(site_url('/site_info/delete').'/${site_id}', 'Delete', 'onclick="return deleteConfirm()"');
				}
				
				if (count($link)) {
					if (count($link) > 1) {
						echo implode(' | ', $link);
					} else {
						echo $link[0];
					}
				}
			}
			?>
			<!-- <a class="updateBtn" href="<?php echo site_url('/site_info/edit') ?>/${editLink}">Edit</a> | <a class="deleteBtn" href="<?php echo site_url('/site_info/delete') ?>/${deleteLink}" onclick="return confirm(\'Are you sure you want to delete?\')">Delete</a> -->
		</td>
	</tr>
</script>

<script>
$(function() {
	
	$.ajax({
		url: '<?php echo site_url('/site_info') ?>',
		data: { cmd: 'GET_MASTER_SITE' },
		dataType: 'json',
		success: function( response ) {
			var j=1;
			for( var i in response ) {
				response[i]['editLink'] = response[i]['site_id'];
				response[i]['deleteLink'] = response[i]['site_id'];
				response[i]['nomor'] = j;
				j++;
			}
			//clear old rows
			$( '#records > tbody' ).html( '' );
			
			//append new rows
			$('#tplMasterSite').render( response ).appendTo( "#records > tbody" );
			
			//apply dataTable to #records table and save its object in dataTable variable
			if( typeof dataTable == 'undefined' )
				dataTable = $( '#records' ).dataTable({"bJQueryUI": true});
			
			//hide ajax loader animation here...
			//$( '#ajaxLoadAni' ).fadeOut( 'slow' );
		}
	});

});

var deleteConfirm = function() {
	return confirm('Are you sure you want to delete?');
};
</script>